/*
	Distance.h
	Christopher Raffaele
	04.28.2008

	Distance's class definitions
*/
#include"DistanceDec.h" //Distance class declarations

//display the first menu
void Distance::showFirstMenu(){
	std::cout << "\n--------------------------------\n"
		 << "\\     Distance: Convert From    \\\n"
		 << " ---------------------------------\n"
		 << " | 1 | Feet                      |\n"
		 << " ---------------------------------\n"
		 << " | 2 | Inches                    |\n"
		 << " ---------------------------------\n"
		 << " | 3 | Miles                     |\n"
		 << " ---------------------------------\n"
 		 << " | 4 | Millimeters               |\n"
		 << " ---------------------------------\n"
 		 << " | 5 | Meters                    |\n"
		 << " ---------------------------------\n"
 		 << " | 6 | Centimeters               |\n"
		 << " ---------------------------------\n";
}

//display the second menu
void Distance::showSecondMenu(){
	std::cout << "\n--------------------------------\n"
		 << "\\      Distance: Convert To     \\\n"
		 << " ---------------------------------\n"
		 << " | 1 | Feet                      |\n"
		 << " ---------------------------------\n"
		 << " | 2 | Inches                    |\n"
		 << " ---------------------------------\n"
		 << " | 3 | Miles                     |\n"
		 << " ---------------------------------\n"
 		 << " | 4 | Millimeters               |\n"
		 << " ---------------------------------\n"
 		 << " | 5 | Meters                    |\n"
		 << " ---------------------------------\n"
 		 << " | 6 | Centimeters               |\n"
		 << " ---------------------------------\n";
}

//prompt for convert from choice
void Distance::start(){
	//continuously ask for units to convert from until 0 is entered
	do{
		showFirstMenu();//show the first menu

		std::cout << "\nConvert distance from (0 to return to main): ";
		std::cin >> from; //set convert from units variable

		//validate input
		if(from > 0 && from < 7){
			char fromString[13] = {' '}; //char array to hold the units converting from

			//set fromString to the units converting from
			switch(from){
				case 1:
					strncpy(fromString,"feet",4);
					break;
				case 2:
					strncpy(fromString,"inches",6);
					break;
				case 3:
					strncpy(fromString,"miles",5);
					break;
				case 4:
					strncpy(fromString,"millimeters",12);
					break;
				case 5:
					strncpy(fromString,"meters",6);
					break;
				case 6:
					strncpy(fromString,"centimeters",12);
					break;
			}
			showSecondMenu(); //show the second menu

			//get the convert to units
			std::cout << "\nConvert " << fromString << " to: "; 
			std::cin >> to;
			
			//validate input
			if(to > 0 && to < 7)
				getDistance(); //get the distance to be converted
			else //number other than 1-6
				std::cout << "\nInvalid Selection\n";
		}else if(from == 0);
		else //number other than 1-6
			std::cout << "\nInvalid Selection\n";
	}while(from != 0);
}

void Distance::getDistance(){
	std::cout << "\nEnter the distance to be converted: ";
	double d; //variable for the distance to be converted
	std::cin >> d;

	//determine what to convert to
	switch(to){
		case 1:
			toFeet(d); //convert entered distance to feet
			break;
		case 2:
			toInches(d); //convert entered distance to inches
			break;
		case 3:
			toMiles(d); //convert entered distance to miles
			break;
		case 4:
			toMillimeters(d); //convert entered distance to millimeters
			break;
		case 5:
			toMeters(d); //convert entered distance to meters
			break;
		case 6:
			toCentimeters(d); //convert entered distance to centimeters
			break;
	}
}

void Distance::toFeet(double distance){
	//based on from units convert passed distance to feet
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance;
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance / 12;
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance * 5280;
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << (distance / (12 * 25.4));
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << (distance / (12 * .0254));
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << (distance / (12 * 2.54));
			break;
	}

	std::cout << "ft\n";
	system("pause"); //wait
}

void Distance::toInches(double distance){
	//based on from units convert passed distance to inches
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance * 12;
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance;
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance * 5280 * 12;
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << (distance /  25.4);
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << (distance / .0254);
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << (distance / 2.54);
			break;
	}

	std::cout << "in\n";
	system("pause"); //wait
}

void Distance::toMiles(double distance){
	//based on from units convert passed distance to miles
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance / 5280;
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance / (5280 * 12);
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance;
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << (distance /  (25.4 * 5280 * 12));
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << (distance / (.0254 * 5280 * 12));
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << (distance / (2.54 * 5280 * 12));
			break;
	}

	std::cout << "mi\n";
	system("pause"); //wait
}

void Distance::toMillimeters(double distance){
	//based on from units convert passed distance to millimeters
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance / (25.4 * 12);
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance / 25.4;
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance / (25.4 * 5280 * 12);
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << distance;
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << distance / 1000;
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << distance / 100;
			break;
	}

	std::cout << "mm\n";
	system("pause"); //wait
}

void Distance::toMeters(double distance){
	//based on from units convert passed distance to meters
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance * .3048;
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance * .0254;
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance * 1609.344;
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << (distance /  1000);
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << distance;
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << (distance / 100);
			break;
	}

	std::cout << "m\n";
	system("pause"); //wait
}

void Distance::toCentimeters(double distance){
	//based on from units convert passed distance to centimeters
	switch(from){
		case 1:
			std::cout << std::endl << distance << "ft is " << distance * 30.48;
			break;
		case 2:
			std::cout << std::endl << distance << "in is " << distance * 2.54;
			break;
		case 3:
			std::cout << std::endl << distance << "mi is " << distance * 160934.4;
			break;
		case 4:
			std::cout << std::endl << distance << "mm is " << (distance /  10);
			break;
		case 5:
			std::cout << std::endl << distance << "m is " << distance * 100;
			break;
		case 6:
			std::cout << std::endl << distance << "cm is " << distance;
			break;
	}

	std::cout << "cm\n";
	system("pause"); //wait
}